package com.ubs.training.server.dao.model;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import javax.persistence.*;

/**
 * Created with IntelliJ IDEA.
 * User: xubuntu
 * Date: 8/21/12
 * Time: 4:36 AM
 * To change this template use File | Settings | File Templates.
 */
@GenericGenerator(name = "CMSTR_SEQ", strategy = "sequence",
        parameters = {@Parameter(name="sequence", value="cmstr_seq")})
@Entity
@Table(name="types",
        uniqueConstraints = {@UniqueConstraint(columnNames={"id"})}
)
public class Type {
    @GeneratedValue(generator = "CMSTR_SEQ")
    @Id
//    @OneToMany
//    @JoinColumn(name = "type_product")
    private int id;
   // @Column
    private String name;

    @OneToMany
    @JoinColumn(name = "type_product")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o){
            return true;
        }
        if (o == null || getClass() != o.getClass()){
            return false;
        }

        Type type = (Type) o;

        if (id != type.id){
            return false;
        }
        if (name != null ? !name.equals(type.name) : type.name != null){
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        return result;
    }
}
